<template>
  <h1>{{ msg }}</h1>
  <button @click="onSend">网页向uni-app传值</button>
  <p>
    Edit <code>components/HelloWorld.vue</code> to test hot module replacement.
  </p>
</template>

<script>
export default {
  name: "HelloWorld",
  props: {
    msg: String,
  },
  data() {
    return {};
  },
  created() {
    window.sendParentData = (res) => {
      console.log(JSON.stringify(res));
      window.alert(JSON.stringify(res));
    };
  },
  methods: {
    onSend() {
      console.log(uni);
      uni.webView.postMessage({
        data: {
          name: "lyt",
          age: 18,
        },
      });
    },
  },
};
</script>
